import axios from "axios";
import router from "@/router";
import conf from "./config";
// 服务项
let api = axios.create({
    baseURL: conf.host,
    timeout: 10000
});
/**
 * 请求拦截
 */
api.interceptors.request.use(config => {
    // 设置请求头
    conf.setHeader(config);
    return config;
}, error => {
    return Promise.reject(error);
});

/**
 * 响应拦截
 */
api.interceptors.response.use(response => {
    var res = JSON.parse(JSON.stringify(response.data));
    if (res.code === "401") {
        // 当接口请求无权限时，进行跳转
        router.replace("/login");
    }
    return res;
}, error => {
    return Promise.reject(error);
});

export default api;